﻿<?php
if (!isset($_SESSION)) {
	session_start();
	if(!isset($_SESSION['username'])){
		$_SESSION['username']='';
	}
}

require_once('lib/connbae.php');

$result1=mysql_query('SELECT * FROM Question ORDER BY post_time DESC LIMIT 10');
$result2=mysql_query('SELECT * FROM Question WHERE qid IN (SELECT qid FROM Answer  ORDER BY post_time DESC )LIMIT 0 , 10');

?>
<!DOCTYPE HTML>
<html>
 <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>C Programing Learning</title>
	<link rel="stylesheet" type="text/css" href="css/base.css"/>
	<link rel="stylesheet" type="text/css" href="css/index.css"/>
	<link href="img/favour.ico" type="image/ico" rel="shortcut icon">
	<script type="text/javascript" src="js/#"></script>
<script>
<!--
function setTab(m,n)
{
	var tli=document.getElementById("menu").getElementsByTagName("li");
	var mli=document.getElementById("main").getElementsByTagName("div");
	
	for(i=0;i<tli.length;i++){
		tli[i].className=i==n?"hover":"";
		mli[i].style.display=i==n?"block":"none";
	}
}
-->
</script>
</head>
<body>
	<div id="content">
		<div id="container">
			<div id="header">				
				<div class="nav">
					<ul>
						<li><a class="logo" href="/" title="Funny C"></a></li>
						<li><a href="/">主页</a></li>
						<li><a href="ask.php">提问</a></li>
						<li><a href="documation.php">资源</a></li>
<?php if(!isset($_SESSION['username'])||$_SESSION['username']=='')
					{
echo "						<li><a href='login.php?action=login'>登录</a></li>
						<li><a href='register.php'>注册</a></li>";
					}else{
echo "						<li><a href='my.php'>个人中心</a></li>
						<li><a href='login.php?action=logout'>注销</a></li>\n";
					} ?>
					</ul>
				</div>				
			</div><hr/>

			<div class="searchbar">
				<form id="frmsearch" class="frmsearch" method="get" action="search.php">
					<label for="key" class="frmlabel">搜一搜</label>
					<input id="key" name="key" rows="1" cols="120" wrap=PHYSICAL class="frmtextarea" placeholder="search..." oninput="checkinput(this.form.title,this.form.total,this.form.used,this.form.remain);" onpropertychange=="checkinput(this.form.title,this.form.total,this.form.used,this.form.remain);"/>
					<span><a href="#search" class="btn">搜索</a></span>
					<span><a href="#ask" class="btn" style="cursor:help;">提问</a></span>
					<span><a href="#answer" class="btn">回答</a></span>
				</form>
			</div><hr/>

			<div id="news">
				<div class="menubox">
					<ul id="menu" class="menu">
						<li onclick="setTab(1,0)" class="hover"><a href="#">待回答问题</a></li>
						<li onclick="setTab(1,1)" class=""><a href="#">已回答问题</a></li>
					</ul>
				</div>
				<div class="mainbox">
					<div id="main" class="main">
						<div class="block" style="display: block;">
<?php while($row1 = mysql_fetch_array($result1))
{
echo "
<p>
	<span>
		<h4>
				<a href='question.php?q={$row1['qid']}'>{$row1['title']}</a>
				<a href='answer.php?q={$row1['qid']}' class='right'>回答</a>
		</h4>
	</span>
	<span>{$row1['content']}</span><hr/>
</p>\n";
}?>
						</div>
						<div style="display: none;">
<?php while($row2 = mysql_fetch_array($result2))
{
echo "
<p>
	<span>
		<h4>
				<a href='question.php?q={$row2['qid']}'>{$row2['title']}</a>
				<a href='answer.php?q={$row2['qid']}' class='right'>回答</a>
		</h4>
	</span>
	<span>{$row2['content']}</span><hr/>
</p>\n";
} ?>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="footer">
			<p>©2014 C语言在线答疑系统 v 1.0</p>
		</div>			
	</div>
</body>
</html>